package com.TWT;

import java.sql.*;

class TicketDatabase {
    private static final String URL = "jdbc:mysql://localhost:3306/tss";
    private static final String USER = "root";
    private static final String PASSWORD = "password";

    public static void saveTransaction(String destination, String ticketType, double price) {
        try (Connection conn = DriverManager.getConnection(URL, USER, PASSWORD);
             PreparedStatement stmt = conn.prepareStatement(
                     "INSERT INTO Transactions (destination, ticket_type, price) VALUES (?, ?, ?)");) {
            stmt.setString(1, destination);
            stmt.setString(2, ticketType);
            stmt.setDouble(3, price);
            stmt.executeUpdate();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public static double getPrice(String ticketType) {
        switch (ticketType) {
            case "Single": return 20.0;
            case "Round-trip": return 35.0;
            case "First Class": return 50.0;
            default: return 20.0;
        }
    }
}
